<template>
  <div class="show-pic">
    <div class="swiper-box">
      <div class="slide" v-if="pics"><pic-zoom :url="pics[imgIndex]" :scale="3"></pic-zoom></div>
      <div class="slide" v-else><pic-zoom :url="noPic" :scale="3"></pic-zoom></div>
    </div>
    <div class="small-box" v-if="pics">
      <div class="small-pic" v-for="(item, index) in pics" :key="index" @click="changeImage(index)"><img :src="item" alt="" /></div>
    </div>
    <div class="small-box" v-else>
      <div class="small-pic"><img :src="noPic" alt="" /></div>
    </div>
  </div>
</template>

<script>
import PicZoom from 'vue-piczoom';

export default {
  name: 'ShowImage',
  components: {
    PicZoom
  },
  props: { 
    pics: Array
  },
  data() {
    return {
      imgIndex: 0,
      noPic: require('assets/images/nopic.jpg')
    };
  },
  created() {
    if (!this.pics) {
    }
  },
  methods: {
    changeImage(index) {
      this.imgIndex = index;
    },
    nextClick() {
      if (this.imgIndex < this.pics.length - 1) {
        this.imgIndex++;
      } else if (this.imgIndex === this.pics.length - 1) {
        this.imgIndex = 0;
      }
    },
    prevClick() {
      if (this.imgIndex > 0) {
        this.imgIndex--;
      } else if (this.imgIndex === 0) {
        this.imgIndex = this.pics.length - 1;
      }
    }
  }
};
</script>

<style scoped>
.show-pic {
  width: 420px;
}
.swiper-box {
  position: relative;
}

.slide >>> .magnifier-box img {
  width: 100%;
  height: 410px;
  object-fit: cover;
  margin: 0 auto;
  display: block;
}

.magnifier-box >>> .mouse-cover {
  background: #000;
  opacity: 0.22;
}

.small-box {
  display: flex;
  flex-wrap: wrap;
}
.small-pic {
  width: 97px;
  height: 95px;
  margin-top: 10px;
  margin-right: 8px;
}
.small-pic img {
  width: 100%;
}
.prev,
.next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  padding: 24px 7px;
  background: #e38b2b;
  display: flex;
  justify-content: center;
  align-items: center;
  outline: none;
}
.prev {
  left: -5px;
}
.next {
  right: -5px;
}
</style>
